<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\finance;

use app\model\ProviderContractDealServiceModel;
use app\model\ProviderContractServiceModel;
use app\model\ProviderModel;

final class ProviderService extends FinanceService
{
    /**
     * 获取服务商名.
     * @param int $providerId 服务商id
     */
    public static function getProviderName(int $providerId = 0): string
    {
        return (new ProviderModel())
            ->where('id', $providerId)
            ->value('provider_name');
    }

    /**
     * 获取服务费率.
     * @param int $type 1合同  2协议
     * @param int $serviceId 服务id
     */
    public static function getProviderService(int $type = 0, int $serviceId = 0): float
    {
        if ($type == 1) {
            $model = new ProviderContractServiceModel();
        } else {
            $model = new ProviderContractDealServiceModel();
        }
        $serviceRate = $model->where('id', $serviceId)
            ->value('service_have_rate') ?: 0;
        return floatval(max($serviceRate, 0));
    }
}
